package br.mestrado.unb.bs.model.sensor;

import br.mestrado.unb.bs.model.constant.DataPackageConstant;
import br.mestrado.unb.bs.util.CopyArrayUtil;

public class DataPackageWrapper {
	
	private PayloadInterface payload;
	
	
	public DataPackageWrapper(PayloadInterface payload) {
		this.payload = payload;
	}
	
	public byte[] toByteStream(){
		if(payload!=null){
			
			byte [] pack = new byte[DataPackageConstant.s_header_size + payload.getSize() ];
			// mount wrap
			pack[DataPackageConstant.i_start_package] 		= DataPackageConstant.s_start_package;
			pack[DataPackageConstant.i_package_size] 		= payload.getSize();
			pack[DataPackageConstant.i_battery] 			= payload.getBattery();
			pack[DataPackageConstant.i_sample_frequency]	= payload.getSampleFrequency();
			pack[DataPackageConstant.i_payload_category] 	= payload.getCategory();
			pack[DataPackageConstant.i_start_payload] 		= DataPackageConstant.s_start_payload;
			pack[pack.length-1]								= DataPackageConstant.s_end_package;

			// fill with payload
			CopyArrayUtil.copyPayloadContent(pack,payload,DataPackageConstant.i_start_payload + 1);
			
			return pack;
		}else{
			return null;
		}
	}

	//GETTERS AND SETTERS
	
	public PayloadInterface getPayload() {
		return payload;
	}

	public void setPayload(PayloadInterface payload) {
		this.payload = payload;
	}

}
